(function () {
  // 卡片组件
  const CardCom = window.VueComponents.CardCom;
  const CardHead = window.VueComponents.CardHead;
  // 影视列表组件
  const VideoList = window.VueComponents.VideoList;
  // 排行榜列表组件
  const TopList = window.VueComponents.TopList;
  // 咨询列表组件
  const ConsultCom = window.VueComponents.ConsultCom;
  // 头部组件
  const Header = window.VueComponents.Header;
  // 底部组件
  const Footer = window.VueComponents.Footer;

  Vue.createApp({
    components: {
      CardCom,
      CardHead,
      VideoList,
      TopList,
      ConsultCom,
      HeaderCom: Header,
      FooterCom: Footer,
    },
    data: () => ({
      typeData: [
        // {
        //   title: "动作片",
        //   titleIcon: undefined,
        //   hotIcon: undefined,
        //   hotTitle: "热度",
        //   id: 0,
        //   items: [], //视频列表
        //   cons: [], //咨询列表
        //   hots: [], //热度列表
        // },
      ],
    }),
    created() {
      //  数据初始化
      this.navInit();
    },
    mounted() {},
    methods: {
      // 方法
      navInit() {
        const query = this.getQueryVariable();
        if (query.type) {
          const queryType = Number(query.type);
          // 影视数据
          const TypeData = window.APIDATA.TypeData;
          // 标签数据
          const TagData = window.APIDATA.TagData;
          // 热度排行数据
          const HotData = window.APIDATA.HotData;

          let type = TypeData(queryType);
          let tag = TagData(queryType);
          let hot = HotData(queryType);

          const temp = [];
          tag.forEach((item) => {
            const tagId = item.id;
            temp.push({
              id: item.id,
              title: item.title,
              hotTitle: item.title + "榜单",
              items: type[item.id].splice(0, 12).map((item) => {
                return {
                  id: item.season_id,
                  title: item.title,
                  pic: item.order,
                  desc: item.subTitle,
                  img: item.cover,
                  href: `second.html?id=${item.season_id}&type=${queryType}&tag=${tagId}`,
                };
              }),
              cons: type[item.id].splice(0, 20).map((item) => ({
                id: item.season_id,
                title: item.title,
                type: item.order,
                href: `second.html?id=${item.season_id}&type=${queryType}&tag=${tagId}`,
              })),
              hots: hot[item.id].splice(0, 20).map((item) => ({
                id: item.season_id,
                title: item.title,
                muted: item.order,
                href: `second.html?id=${item.season_id}&type=${queryType}&tag=${tagId}&hot=1`,
              })),
            });
          });

          this.typeData = temp;
        } else {
          console.log("参数错误");
        }
      },
      // 获取参数
      getQueryVariable(variable) {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        let queryValue = {};
        vars.forEach((pair) => {
          if (pair.indexOf("=") != -1) {
            const item = pair.split("=");
            queryValue[item[0]] = item[1];
          }
        });
        return queryValue;
      },
    },
  }).mount("#app-dy");
})();
